package main

import (
	"gitee.com/thubcc/mobile/lte"
	"gitee.com/thubcc/rtlmmap"
	"github.com/prometheus/common/log"
)

var (
	view = rtlmmap.NewRtlView(0, rtlmmap.DefaultLTEConfig)
)

func pss_search2D() {
	ftco := view.GetFTco()
	ftco.InitPPM()
	rfd := view.Raw(0, 2)
	view.Run(2)
	idx, amp, _ := lte.ScanPssAll.SearchPSS2D(rfd, 874.2e6)
	df := float64(lte.ScanPssAll.Frequency(idx[1]))
	pos := (9600 - 960 + idx[2] + 128) % 9600
	log.Info("Searching ", idx[0], df, pos, amp)
	if df < 3e3 {
		log.Info("AFC by Ref")
		rs := lte.ScanRefSym(rfd, idx[0], 0, pos)
		df = rs[0].Df
		log.Info(rs[0].Amp, rs[0].Cid, rs[0].Pos, rs[0].Df)
	}
	ftco.PPMF(df)
}

func pss_search() {
	ftco := view.GetFTco()
	ftco.InitPPM()
	view.HardReset()
	view.Reset()
	rfd := view.Raw(0, 100)
	df, amp, t, pos := lte.ScanPssAll.SearchPSS(rfd, 874.2e6)
	log.Info("Searching ", df, amp, t, pos)
	ftco.PPMF(df)
}

func main() {
	view.HardReset()
	view.Reset()
	pss_search2D()
	// pss_search()
}
